package diamondexercises;

import static diamondexercises.Utilities.readInputFromConsole;

/**
 * Created by ravindra on 18/7/14.
 */

class DriveIsoscelesTriangle{
    public static void main(String[] Args){
        int size;
        String input = null;
        IsoscelesTriangle isoscelesTriangle = new IsoscelesTriangle();
        System.out.println("To exit type -> quit. \n");

        input = readInputFromConsole("size");

        while(!input.equals("quit")){
            size = Integer.parseInt(input);
            String isoscelesTriangleString = isoscelesTriangle.generate(size);
            System.out.println(isoscelesTriangleString);

            input = readInputFromConsole("size");
        }
    }
}

class IsoscelesTriangle {
    StringBuilder isoscelesTriangle = new StringBuilder();

    void padWithSpaces(int noOfSpaces){
        for(int i = 0; i < noOfSpaces; i++){
            isoscelesTriangle.append(" ");
        }
    }

    public String generate(int size) {
        int noOfSpaces = size - 1;

        for(int i = 0; i < size; i++){
            padWithSpaces(noOfSpaces);
            noOfSpaces--;
            int noOfAsterisk = (2 * i) + 1;

            for(int j = 0; j < noOfAsterisk ; j++){
                isoscelesTriangle.append("*");
            }

            isoscelesTriangle.append("\n");
        }
        return isoscelesTriangle.toString();
    }


}
